import { ref } from 'vue'
import { getSingers } from '@/service/find-music/singer-search'
export function InitDoing() {
  const idOne = ref(-1)
  const idTwo = ref(-1)
  const idThree = ref<number | string>(-1)
  const singers = ref([])
  const defaultLimit = ref(30)
  // 语种
  const changeOne = (id: number) => {
    defaultLimit.value = 30
    idOne.value = id
    getSingerData(idOne.value, idTwo.value, idThree.value)
  }
  // 分类
  const changeTwo = (id: number) => {
    defaultLimit.value = 30
    idTwo.value = id
    getSingerData(idOne.value, idTwo.value, idThree.value)
  }
  // 筛选
  const changeThree = (id: number | string) => {
    defaultLimit.value = 30
    idThree.value = id
    getSingerData(idOne.value, idTwo.value, idThree.value)
  }
  //获取对应歌手数据
  function getSingerData(
    area: number,
    type: number,
    initial: number | string,
    limit = defaultLimit.value
  ) {
    getSingers(area, type, initial, limit).then((res: any) => {
      singers.value = res.artists
    })
  }
  // 无限滚动获取数据
  const handelRequest = () => {
    getSingerData(idOne.value, idTwo.value, idThree.value)
    defaultLimit.value += 30
  }
  return {
    changeOne,
    changeTwo,
    changeThree,
    singers,
    handelRequest
  }
}
